﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IPropertyDeclarationExtensions.cs" company="StyleCop for ReSharper Development Team">
//   Copyright (c) StyleCop for ReSharper Development Team. All rights reserved.
// </copyright>
// <summary>
//   Defines the IPropertyDeclarationExtensions type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace JetBrains.ReSharper.Psi.CSharp.Tree
{
    /// <summary>
    /// I property declaration extensions.
    /// </summary>
    public static class IPropertyDeclarationExtensions
    {
        #region Public Methods

        /// <summary>
        /// Getter.
        /// </summary>
        /// <param name="propertyDeclaration">
        /// The property declaration.
        /// </param>
        /// <returns>
        /// </returns>
        public static IAccessor Getter(this IPropertyDeclaration propertyDeclaration)
        {
            foreach (var declaration in propertyDeclaration.AccessorDeclarations)
            {
                var accessor = (IAccessor)declaration.DeclaredElement;

                if (accessor != null && accessor.Kind == AccessorKind.GETTER)
                {
                    return accessor;
                }
            }

            return null;
        }

        /// <summary>
        /// Setter.
        /// </summary>
        /// <param name="propertyDeclaration">
        /// The property declaration.
        /// </param>
        /// <returns>
        /// </returns>
        public static IAccessor Setter(this IPropertyDeclaration propertyDeclaration)
        {
            foreach (var declaration in propertyDeclaration.AccessorDeclarations)
            {
                var accessor = (IAccessor)declaration.DeclaredElement;

                if (accessor != null && accessor.Kind == AccessorKind.SETTER)
                {
                    return accessor;
                }
            }

            return null;
        }

        #endregion
    }
}